﻿using System.Collections.Generic;
using UnityEngine;

namespace FastDev
{
    public class GoapState
    {
        public Dictionary<string, int> Values { get; private set; }

        public GoapState()
        {
            Values = new Dictionary<string, int>();
        }

        public GoapState(Dictionary<string, int> values)
        {
            this.Values = new Dictionary<string, int>(values);
        }

        public void SetValue(string key, int value)
        {
            Values[key] = value;
        }

        public int GetValue(string key)
        {
            if (Values.ContainsKey(key))
            {
                return Values[key];
            }
            return -1;
        }

        public bool Contains(KeyValuePair<string, int> b)
        {
            if (!Values.ContainsKey(b.Key) || Values[b.Key] < b.Value)
            {
                return false;
            }
            return true;
        }

        public bool Contains(GoapState b)
        {
            if(b == null)
            {
                return false;
            }
            foreach (var k in b.Values)
            {
                if (Contains(k) == false)
                {
                    return false;
                }
            }
            return true;
        }

        public bool Contains(GoapState b,ref string unmatchedKey)
        {
            foreach (var k in b.Values)
            {
                if (Contains(k) == false)
                {
                    unmatchedKey = k.Key;
                    return false;
                }
            }
            return true;
        }
    }
}
